//
//  GYHomeTopCell.m
//  GYDemo
//
//  Created by Mrzhang on 2018/3/30.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYHomeTopCell.h"
#import "Head.h"
@interface GYHomeTopCell ()<SDCycleScrollViewDelegate>
@property(nonatomic,strong)SDCycleScrollView* bannerScroll;
@property(nonatomic,strong)SDCycleScrollView* textScroll;
@property(nonatomic,strong)UIView* middleView;
@property(nonatomic,strong)UIImageView* markIV;

@end

@implementation GYHomeTopCell
-(UIImageView *)markIV
{
    
    if (!_markIV) {
        _markIV=[[UIImageView alloc] init];
        _markIV.image=[UIImage imageNamed:@"home_price_mark"];
        _markIV.x=8;
        _markIV.y=0;
        _markIV.width=_markIV.image.size.width;
        _markIV.height=_markIV.image.size.height;
    }
    return _markIV;
    
}
-(SDCycleScrollView *)bannerScroll
{
    if (!_bannerScroll) {
        _bannerScroll=[SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, WFCGFloatY(214)) delegate:self placeholderImage:DefaultImage];
        _bannerScroll.backgroundColor=Main_Color_BGLightGray;
        _bannerScroll.currentPageDotColor=[UIColor whiteColor];
        _bannerScroll.pageDotColor=RGBACOLOR(216, 216, 216, 0.5);
        _bannerScroll.pageControlBottomOffset=5;
    }
    return _bannerScroll;
}

-(SDCycleScrollView *)textScroll
{
    if (!_textScroll) {
        _textScroll=[SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(WFCGFloatX(80), 0, WFCGFloatX(357-80), WFCGFloatY(25)) delegate:self placeholderImage:nil];
        _textScroll.backgroundColor=[UIColor whiteColor];
        _textScroll.scrollDirection=UICollectionViewScrollDirectionVertical;
        _textScroll.titleLabelTextAlignment=NSTextAlignmentLeft;
        _textScroll.titleLabelTextColor=Main_Color_Black;
        _textScroll.titleLabelTextFont=SYSTEMFONT(13);
        _textScroll.onlyDisplayText=YES;
        _textScroll.titleLabelBackgroundColor=[UIColor whiteColor];
        [WFFunctions WFUIaddbordertoView:_textScroll radius:WFCGFloatY(12) width:0 color:[UIColor clearColor]];
    }
    return _textScroll;
}
-(UIView *)middleView
{
    if (!_middleView) {
        _middleView=[[UIView alloc] init];
        _middleView.frame=WFCGRectMake(9, 225, 375-18, 120);
        _middleView.backgroundColor=[UIColor whiteColor];
        //[WFFunctions addCornerToView:_middleView radius:10 corner:UIRectCornerTopLeft|UIRectCornerTopRight];
        [WFFunctions WFUIaddbordertoView:_middleView radius:10 width:0 color:[UIColor clearColor]];
        
        NSArray* btnArr=@[@{@"image":@"home_btn_1",@"name":@"现货资源"},
                          @{@"image":@"home_btn_2",@"name":@"求购信息"},
                          @{@"image":@"home_btn_3",@"name":@"行情中心"}
                          ];
        
        UIImage* img=[UIImage imageNamed:[btnArr[0] objectForKey:@"image"]];
        float imageWith=img.size.width;
        float ww=(375-18-imageWith*3)/4;
        
        for (int i=0; i<btnArr.count; i++)
        {
            
            UIButton* btn=[UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame=WFCGRectMake(ww+(imageWith+ww)*(i%3),43+(42+imageWith)*(i/3), imageWith, imageWith);
            [btn setBackgroundImage:[UIImage imageNamed:[btnArr[i] objectForKey:@"image"]] forState:UIControlStateNormal];
            [_middleView addSubview:btn];
            btn.tag=100+i;
            [btn addTarget:self action:@selector(btnPress:) forControlEvents:UIControlEventTouchUpInside];
            
            UILabel* lab=[[UILabel alloc] init];
            lab.text=[btnArr[i] objectForKey:@"name"];
            lab.frame=WFCGRectMake(ww/2+(ww+imageWith)*(i%3), (48+imageWith)+(imageWith+43)*(i/3), ww+imageWith, 16.5);
            lab.font=SYSTEMFONT(13);
            lab.textAlignment=NSTextAlignmentCenter;
            lab.textColor=HEXCOLOR(@"#333333");
            [_middleView addSubview:lab];
        }
    }
    return _middleView;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self= [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self.contentView addSubview:self.bannerScroll];
        [self.contentView addSubview:self.middleView];
        [self.middleView addSubview:self.textScroll];
        [self.middleView addSubview:self.markIV];
        
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    NSMutableArray* imageArr=[[NSMutableArray alloc] init];
    
    for (GYHomeBuyProductInfoModel*mode in _BnnerArr)
    {//kBannerImgSuffix
        [imageArr addObject:mode.imgpath];
    }
    _bannerScroll.imageURLStringsGroup=imageArr;
}

#pragma method

-(void)btnPress:(UIButton*)sender
{

    _cellback([NSString stringWithFormat:@"%ld",sender.tag],3);
}
#pragma mark delegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (cycleScrollView==_bannerScroll)
    {
        GYHomeBuyProductInfoModel*model=_BnnerArr[index];
        
        _cellback(model.shopid,1);
    }
    if (cycleScrollView==_textScroll)
    {
        _cellback(@"",2);
    }
}

@end
